package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;

public class ReflectDemo12 {
    public static void main(String[] args) throws Exception {
        // 判断Person上的方法是否被AutoRunClass注解
        Class cls = Class.forName("reflect.Person");

        Method methods = cls.getDeclaredMethod("sayHi");
        if (methods.isAnnotationPresent(AutoRunClass.class)) {
            System.out.println("该方法被注解了");
        } else {
            System.out.println("该方法没有被注解");
        }
        // 输出Person类中被@AutoRunClass注解的方法

        Method[] methods1 = cls.getDeclaredMethods();
        for (Method method : methods1) {
            if (method.isAnnotationPresent(AutoRunMethod.class)) {
                System.out.println("被@AutoRunMethod注解的方法有：" + method.getName());
            }
        }
    }
}
